# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python

from cerbero.tools.libtool import LibtoolLibrary
from cerbero.utils import shell
import shutil

class Recipe(recipe.Recipe):
    name = 'libsrtp'
    version = '1.6.0'
    stype = SourceType.TARBALL
    url = 'https://github.com/cisco/%(name)s/archive/v%(version)s.tar.gz'
    tarball_checksum = '1a3e7904354d55e45b3c5c024ec0eab1b8fa76fdbf4dd2ea2625dad2b3c6edde'
    licenses = [{License.BSD_like: ['LICENSE']}]
    patches = ['libsrtp/0001-Don-t-create-a-symlink-if-there-is-no-SHAREDLIBVERSI.patch',
               'libsrtp/0002-ios-Remove-flags-incompatible-with-fembed-bitcode.patch']

    files_libs = ['libsrtp']
    files_devel = ['include/srtp', 'lib/pkgconfig/libsrtp.pc']

    def prepare(self):
        # Don't accidentially build with pcap support
        self.set_env('ac_cv_lib_pcap_pcap_create', 'no')
        self.make += ' all shared_library'

    def install(self):
        super(Recipe, self).install()
        libdir = os.path.join(self.config.prefix,
                              'lib' + self.config.lib_suffix)
        shutil.copy(os.path.join(self.build_dir, 'srtp.def'), libdir)

    def post_install(self):
        libtool_la = LibtoolLibrary('srtp', 1, None, None, self.config.libdir,
                                    self.config.target_platform)
        libtool_la.save()
        super().post_install()
